﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testgit
{
    class Template
    {
    }
    class CLinkNode
    {
        public CLinkNode(object v)
        {
            Value = v;
        }
        public object Value { get; set; }
        public CLinkNode Pre { get; set;}     
        public CLinkNode Next {get; set;}
    }
    class CLinkList : IEnumerable
    {
        public CLinkNode First { set; get; }
        public CLinkNode Last { set; get; }
        public CLinkNode addNode(object obj)
        {
            var newNode = new CLinkNode(obj);
            if(First == null)
            {
                First = newNode;
                Last = newNode;
            }else
            {
                CLinkNode previous = Last;
                Last = newNode;
                previous.Next = newNode;
                newNode.Pre = previous;
            }
            return newNode;
        }
        public IEnumerator GetEnumerator()
        {
            CLinkNode node = First;
            while(node != null)
            {
                yield return node;
                node = node.Next;
            }
        }
        public static void TestCode()
        {
            CLinkList list = new CLinkList();
            list.addNode(1);
            list.addNode(1);
            list.addNode(1);
            list.addNode(1);
            list.addNode(1);
            list.addNode(1);
            list.addNode(1);
            foreach (CLinkNode i in list)
            {
                int tmp = (int)i.Value;
                Console.WriteLine(tmp);
            }
        }
       
    }

    class TLinkNode<T>
    {
        public TLinkNode(T obj)
        {
            Value = obj;
        }
        public T Value { get; set; }
        public TLinkNode<T> Pre { get; set; }
        public TLinkNode<T> Next { get; set; }
    }
    class TLinkList<T> : IEnumerable<T>
    {
        public TLinkNode<T> First { set; get; }
        public TLinkNode<T> Last { set; get; }

        public TLinkNode<T> addNode(T obj)
        {
            TLinkNode<T> newNode = new TLinkNode<T>(obj);
            if (First == null)
            {
                First = newNode;
                Last = newNode;
            }
            else
            {
                TLinkNode<T> previous = Last;
                Last = newNode;
                previous.Next = newNode;
                newNode.Pre = previous;
            }
            return newNode;
        }


        public IEnumerator<T> GetEnumerator()
        {
            TLinkNode<T> node = First;
            while (node != null)
            {
                yield return node.Value;
                node = node.Next;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public static void TestCode()
        {
            TLinkList<int> list = new TLinkList<int>();
            list.addNode(2);
            list.addNode(123);
            list.addNode(134);
            list.addNode(9535);
            list.addNode(424);
            list.addNode(9355);
            foreach (int i in list)
            {
                Console.WriteLine(i);
            }
        }
    }
    public abstract class  Calc<T>
    {
        public abstract T Add(T x, T y);
        public abstract T Sub(T x, T y);
    }
    public class CalcInt : Calc<int>
    {
        public override int Add(int x, int y)
        {
            return x + y;
        }

        public override int Sub(int x, int y)
        {
            return x - y;
        }
    }

    public interface IDocument
    {
        string Title { get; set; }
        string Content { get; set; }
    }

    public class CDocument : IDocument
    {
        public CDocument(){}
        public CDocument(string title, string content)
        {
            this.Title = title;
            this.Content = content;
        }
        public string Title {set; get;}
        public string Content {set; get;}
    }

    class CDocumentManager<T>
        where T : IDocument, new()
    {
        public CDocumentManager()
        {
            DocGroup = new List<T>();
        }
        public List<T> DocGroup;
        public void addDoc(T doc)   
        {
            DocGroup.Add(doc);
        }
        public void showAllDoc()
        {
            foreach(T i in DocGroup)
            {
                Console.WriteLine(i.Title + "       " + i.Content);
            }
        }
        public static void TestCode()
        {
            CDocument tmp1 = new CDocument("1", "1111");
            CDocument tmp2 = new CDocument("2", "2222");
            CDocument tmp3 = new CDocument("3", "33333");
            CDocument tmp4 = new CDocument("4", "44444");
            CDocument tmp5 = new CDocument("5", "55555");
            CDocument tmp6 = new CDocument("6", "66666");
            CDocument tmp7 = new CDocument("7", "77777");
            CDocumentManager<CDocument> manager = new CDocumentManager<CDocument>();
            manager.addDoc(tmp1);
            manager.addDoc(tmp2);
            manager.addDoc(tmp3);
            manager.addDoc(tmp4);
            manager.addDoc(tmp5);
            manager.addDoc(tmp6);
            manager.addDoc(tmp7);
            manager.showAllDoc();
        }
    }
}
       
